{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "1fb78d38",
   "metadata": {},
   "source": [
    "## 上周回顾\n",
    "\n",
    "> * 1.list的一般方法/一般函数的使用及案例，如：\n",
    ">> 1. append()增加，增加list元素到list的末尾，常用于新建列表\n",
    ">> 2. pop(index)/remove(values)对比两者优势\n",
    ">> 3. count()查看某个元素出现的次数\n",
    ">> 4. index()查看某个元素第一次出现的位置\n",
    ">> 5. extend()两个list合并在一起，也可用[]+[]来实现\n",
    ">> 6. sort() list元素的排序\n",
    "\n",
    "> * 2. list的高级用法\n",
    ">> 1. copy()list（可变的数据类型）复制 不等价于 赋值，可用[:]来实现\n",
    ">> 2.enumerate() 枚举，可同时遍历并获取index和values\n",
    "\n",
    "## 本周内容:\n",
    "\n",
    "### list练习，vowels.py vowels2.py\n",
    "\n",
    "### list实践：\n",
    "\n",
    "### 初始字典\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "7062ad56",
   "metadata": {},
   "outputs": [],
   "source": [
    "name = \"zhichao\"\n",
    "name = \"youge\"\n",
    "name"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d4e86ded",
   "metadata": {},
   "outputs": [],
   "source": []
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d9079392",
   "metadata": {},
   "outputs": [],
   "source": [
    "vowels = ['a','e','i','o','u']\n",
    "word = \"Milliways\"\n",
    "# 检查 word中出现的 原因， 并打印出来 怎么做？\n",
    "# for letter in word:    #  第一个元素letter 请不要和已有变量重名\n",
    "                         #  第一个元素一般不定义名字，常用item（内容）来命名\n",
    "                         #                            简写 i 来命名\n",
    "                         #  第二个元素word（重要），意味着将遍历的内容\n",
    "                         #  遍历的内容一般是 序列数据 str list\n",
    "                         \n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "    if letter in vowels:\n",
    "        print(letter)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "804eebc4",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 使用append() 新建列表\n",
    "found = []\n",
    "for letter in word:\n",
    "#     print(letter)\n",
    "    if letter in vowels:   # letter 在 元音字母表中\n",
    "        if found not in found:   # letter 不在found表中\n",
    "            found.append(letter)     \n",
    "        \n",
    "found\n",
    "\n",
    "\n",
    "\n",
    "\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "b2309a01",
   "metadata": {},
   "outputs": [],
   "source": [
    "### list实践："
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e2688c27",
   "metadata": {},
   "outputs": [],
   "source": [
    "money = input(\"请输入您的余额：\")\n",
    "print(\"① 一支铅笔 2元\")\n",
    "print(\"② 一支钢笔 2元\")\n",
    "print(\"③ 一个橡皮擦 2元\")\n",
    "print(\"④ 一瓶水 2元\")\n",
    "print(\"⑤ 一个水杯 2元\")\n",
    "\n",
    "    number = input(\"请输入您想购买的商品编号，如，①号商品的编号为1: \")\n",
    "            \n",
    "            "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "889a25d3",
   "metadata": {},
   "outputs": [
    {
     "ename": "SyntaxError",
     "evalue": "invalid character in identifier (<ipython-input-1-9d4c0fd633f0>, line 3)",
     "output_type": "error",
     "traceback": [
      "\u001b[1;36m  File \u001b[1;32m\"<ipython-input-1-9d4c0fd633f0>\"\u001b[1;36m, line \u001b[1;32m3\u001b[0m\n\u001b[1;33m    [\"华为手机\",8000]，\u001b[0m\n\u001b[1;37m                 ^\u001b[0m\n\u001b[1;31mSyntaxError\u001b[0m\u001b[1;31m:\u001b[0m invalid character in identifier\n"
     ]
    }
   ],
   "source": [
    "# 商品信息的数据存放（商品名称，商品价格，商品的编号）\n",
    "goods_list = [ [\"python课本\",60],   # 我们认为 每一个商品的内容是一个多个值的值，可选用list\n",
    "               [\"华为手机\",8000]，\n",
    "               [\"小米手环\",200]，\n",
    "               [\"蜜雪冰城\",8]\n",
    "             ] \n",
    "# 用户输入购物信息的数据存放\n",
    "uesr_shopping_list = [] # 增加进来可考虑用append()方法\n",
    "\n",
    "# 用户输入余额信息\n",
    "Alipay = input(\"请输入支付宝余额：\")\n",
    "# 打印商品信息\n",
    "info = '''------- goods list --------\n",
    "商品编号：%s,商品名称： %s，商品价格： %s 元\n",
    "商品编号：%s,商品名称： %s，商品价格： %s 元\n",
    "商品编号：%s,商品名称： %s，商品价格： %s 元\n",
    "商品编号：%s,商品名称： %s，商品价格： %s 元\n",
    "\n",
    "'''%(0,good_list[0][0],goods_list[0][1],\n",
    "     1,good_list[1][0],goods_list[1][1],\n",
    "     2,good_list[2][0],goods_list[2][1],\n",
    "     3,good_list[3][0],goods_list[3][1],\n",
    ")\n",
    "print(info)\n",
    "# list的长度? len()\n",
    "print('--------------- goods list ----------------')\n",
    "for i in range(len(goods_list)):\n",
    "    print(\"商品编号：%s,商品名称： %s，商品价格： %s 元\"%(i,goods_list[i][0]))\n",
    "\n",
    "    \n",
    "# 用户输入商品编号，实现商品的查询\n",
    "choice = int(input(\"请输入商品的编号：\"))  # input输入的内容默认是字符串str 例如输入2，则显示\n",
    "# 判断编号是否存在\n",
    "if choice < len(goods_list):\n",
    "    # 检查 用户余额 > 商品价格\n",
    "    if Alipay > good_list[choice][1]:\n",
    "        Alipay = Alipay - goods_list[choice][1] # 用户余额发生变化，要扣除\n",
    "        user_shopping_list.append(goods_list[choice])\n",
    "        pass\n",
    "    else:\n",
    "        print(\"您的余额已不足，请更换支付方式，试试花呗？\")\n",
    "\n",
    "else:\n",
    "    print(\"请输入正确的商品编号，您输入的商品不存在\")\n",
    "    \n",
    "    \n",
    "# 打印用户余额和用户的商品列表信息\n",
    "print(\"用户余额： %s,购物车： %s\"%(Alipay,user_shopping_list))\n",
    "\n",
    "\n",
    "\n",
    "#"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "d6fe1d93",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
